use utf8;
package iSOCK::Schema::App::Result::Product;

# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE

=head1 NAME

iSOCK::Schema::App::Result::Product

=cut

use strict;
use warnings;

use Moose;
use MooseX::NonMoose;
use MooseX::MarkAsMethods autoclean => 1;
extends 'DBIx::Class::Core';

=head1 COMPONENTS LOADED

=over 4

=item * L<DBIx::Class::InflateColumn::DateTime>

=back

=cut

__PACKAGE__->load_components("InflateColumn::DateTime");

=head1 TABLE: C<product>

=cut

__PACKAGE__->table("product");

=head1 ACCESSORS

=head2 id

  data_type: 'varchar'
  is_nullable: 0
  size: 256

=head2 specification_id

  data_type: 'varchar'
  is_foreign_key: 1
  is_nullable: 1
  size: 256

=head2 stage_id

  data_type: 'varchar'
  is_foreign_key: 1
  is_nullable: 1
  size: 256

=head2 process_id

  data_type: 'varchar'
  is_foreign_key: 1
  is_nullable: 1
  size: 256

=head2 integration_scm_url

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 integration_scm_type_id

  data_type: 'varchar'
  is_foreign_key: 1
  is_nullable: 1
  size: 256

=head2 integration_config_chip_id

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 integration_config_technology_id

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 integration_scm_login

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 integration_scm_password

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 die_id

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 busy

  data_type: 'boolean'
  is_nullable: 1

=head2 ahead

  data_type: 'boolean'
  is_nullable: 1

=head2 integration_scm_branch

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 specification_branch

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 integration_wiki_id

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 pm_id

  data_type: 'varchar'
  is_nullable: 1
  size: 256

=head2 dead

  data_type: 'boolean'
  is_nullable: 1

=cut

__PACKAGE__->add_columns(
  "id",
  { data_type => "varchar", is_nullable => 0, size => 256 },
  "specification_id",
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 256 },
  "stage_id",
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 256 },
  "process_id",
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 256 },
  "integration_scm_url",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "integration_scm_type_id",
  { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 256 },
  "integration_config_chip_id",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "integration_config_technology_id",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "integration_scm_login",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "integration_scm_password",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "die_id",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "busy",
  { data_type => "boolean", is_nullable => 1 },
  "ahead",
  { data_type => "boolean", is_nullable => 1 },
  "integration_scm_branch",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "specification_branch",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "integration_wiki_id",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "pm_id",
  { data_type => "varchar", is_nullable => 1, size => 256 },
  "dead",
  { data_type => "boolean", is_nullable => 1 },
);

=head1 PRIMARY KEY

=over 4

=item * L</id>

=back

=cut

__PACKAGE__->set_primary_key("id");

=head1 RELATIONS

=head2 integration_scm_type

Type: belongs_to

Related object: L<iSOCK::Schema::App::Result::ScmType>

=cut

__PACKAGE__->belongs_to(
  "integration_scm_type",
  "iSOCK::Schema::App::Result::ScmType",
  { id => "integration_scm_type_id" },
  {
    is_deferrable => 1,
    join_type     => "LEFT",
    on_delete     => "CASCADE",
    on_update     => "CASCADE",
  },
);

=head2 process

Type: belongs_to

Related object: L<iSOCK::Schema::App::Result::Process>

=cut

__PACKAGE__->belongs_to(
  "process",
  "iSOCK::Schema::App::Result::Process",
  { id => "process_id" },
  {
    is_deferrable => 1,
    join_type     => "LEFT",
    on_delete     => "CASCADE",
    on_update     => "CASCADE",
  },
);

=head2 product_to_devices

Type: has_many

Related object: L<iSOCK::Schema::App::Result::ProductToDevice>

=cut

__PACKAGE__->has_many(
  "product_to_devices",
  "iSOCK::Schema::App::Result::ProductToDevice",
  { "foreign.product_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 products_to_freeze

Type: has_many

Related object: L<iSOCK::Schema::App::Result::ProductToFreeze>

=cut

__PACKAGE__->has_many(
  "products_to_freeze",
  "iSOCK::Schema::App::Result::ProductToFreeze",
  { "foreign.product_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 specification

Type: belongs_to

Related object: L<iSOCK::Schema::App::Result::Specification>

=cut

__PACKAGE__->belongs_to(
  "specification",
  "iSOCK::Schema::App::Result::Specification",
  { id => "specification_id" },
  {
    is_deferrable => 1,
    join_type     => "LEFT",
    on_delete     => "CASCADE",
    on_update     => "CASCADE",
  },
);

=head2 stage

Type: belongs_to

Related object: L<iSOCK::Schema::App::Result::Stage>

=cut

__PACKAGE__->belongs_to(
  "stage",
  "iSOCK::Schema::App::Result::Stage",
  { id => "stage_id" },
  {
    is_deferrable => 1,
    join_type     => "LEFT",
    on_delete     => "CASCADE",
    on_update     => "CASCADE",
  },
);

=head2 user_to_products

Type: has_many

Related object: L<iSOCK::Schema::App::Result::UserToProduct>

=cut

__PACKAGE__->has_many(
  "user_to_products",
  "iSOCK::Schema::App::Result::UserToProduct",
  { "foreign.product_id" => "self.id" },
  { cascade_copy => 0, cascade_delete => 0 },
);

=head2 devices

Type: many_to_many

Composing rels: L</product_to_devices> -> device

=cut

__PACKAGE__->many_to_many("devices", "product_to_devices", "device");


# Created by DBIx::Class::Schema::Loader v0.07033 @ 2013-01-07 10:38:23
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:PIqkH2ZexPQdYmrYzTczpg

use Sort::Naturally qw( ncmp );

sub secure {
  my ( $self ) = @_;
  
  if ( my $specification_r = $self->specification ) {
    return $specification_r->secure;
  }
  
  return 0;
}

sub integration_wiki_url {
  my ( $self ) = @_;
    
  if ( my $wiki_id = $self->integration_wiki_id ) {
    return "http://penfret.rfo.atmel.com/twiki/bin/view/DesignIntegration/${wiki_id}_Project_Status";
  }
  
  return;
}

sub integration_wiki_url_as_html_a {
  my ( $self ) = @_;
  
  if ( my $wiki_url = $self->integration_wiki_url ) {
    return "<a href=\"$wiki_url\">" . $self->integration_wiki_id . "</a>";
  }
  
  return;
}

sub published_device_rs {
  my ( $self ) = @_;
  
  return sort { ncmp ( $a->id, $b->id ) } map { $_->device } grep { $_->device->url } $self->product_to_devices;
}

# You can replace this text with custom code or comments, and it will be preserved on regeneration
__PACKAGE__->meta->make_immutable;
1;
